/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Desarrollo.Soft.Hibernate.ViewPrincipal.views;

import Desarrollo.Soft.Hibernate.Data.Entity.Tblalmacen;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author r0ck3r
 */
public class intFrmProductosVenta extends javax.swing.JInternalFrame {

    /**
     * Creates new form intFrmProductosVenta
     */
    
    private intFrmVentas venta;
    private DefaultTableModel modelo = new DefaultTableModel();
    private List<Tblalmacen> listaAlmacen;
    
    public intFrmProductosVenta() {
        initComponents();
    }
    
    public intFrmProductosVenta(intFrmVentas _venta, List<Tblalmacen> _listaAlmacen) {
        initComponents();
        this.venta = _venta;
        this.listaAlmacen = _listaAlmacen;
        cargarTitulosTabla();
        cargarTabla();
    }
   
    private void cargarTitulosTabla()
     {
         try {
             String[] titulos = {"Producto","Precio","Unidad Medida",};
             this.modelo.setColumnIdentifiers(titulos);
             tblProductos.setModel(modelo);
         } catch (Exception e) {
             System.out.print(e.getMessage());
         }
     }
    
    private void cargarTabla()
    {
        try {
              for (int i = tblProductos.getRowCount()-1; i >= 0; i--) {
                 modelo.removeRow(i);
            }
            for (int i = 0; i < listaAlmacen.size(); i++) {
                String[] arr = new String[3];
                arr[0] = listaAlmacen.get(i).getCatproductos().getValor();
                arr[1] = listaAlmacen.get(i).getPrecioUnitario().toString();
                arr[2] = listaAlmacen.get(i).getUnidadmedida();
                modelo.addRow(arr);
            }
            tblProductos.setModel(modelo);
        } catch (Exception e) {
            System.out.print(e.getMessage());
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblProductos = new javax.swing.JTable();

        tblProductos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblProductos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblProductosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblProductos);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 488, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 4, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblProductosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblProductosMouseClicked
        try {
            int row = tblProductos.getSelectedRow();
            venta.CargarCampos(listaAlmacen.get(row));
            this.dispose();
        } catch (Exception e) {
              System.out.print(e.getMessage());
        }
    }//GEN-LAST:event_tblProductosMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblProductos;
    // End of variables declaration//GEN-END:variables
}
